﻿using System;
using System.Data;
using System.Collections.Generic;
using Chenxin.Lib.Hr.Entity;
namespace Chenxin.Lib.Hr.BLL
{
    /// <summary>
    /// 业务逻辑类Hr_BlackList 的摘要说明。
    /// </summary>
    public class Hr_BlackList
    {
        public Hr_BlackList()
        { }
        #region  成员方法

        //Cache服务类
        private Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.HR);

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Chenxin.Lib.Hr.Entity.Hr_BlackList model)
        {
            Chenxin.Lib.Hr.DAL.Hr_BlackList.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Chenxin.Lib.Hr.Entity.Hr_BlackList model)
        {
            Chenxin.Lib.Hr.DAL.Hr_BlackList.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(Guid RecordId)
        {

            Chenxin.Lib.Hr.DAL.Hr_BlackList.Delete(RecordId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Chenxin.Lib.Hr.Entity.Hr_BlackList GetModel(Guid RecordId)
        {

            return Chenxin.Lib.Hr.DAL.Hr_BlackList.GetModel(RecordId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return Chenxin.Lib.Hr.DAL.Hr_BlackList.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Hr.Entity.Hr_BlackList> GetModelList(string strWhere)
        {
            DataSet ds = Chenxin.Lib.Hr.DAL.Hr_BlackList.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Hr.Entity.Hr_BlackList> DataTableToList(DataTable dt)
        {
            List<Chenxin.Lib.Hr.Entity.Hr_BlackList> modelList = new List<Chenxin.Lib.Hr.Entity.Hr_BlackList>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Chenxin.Lib.Hr.Entity.Hr_BlackList model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Chenxin.Lib.Hr.Entity.Hr_BlackList();
                    if (dt.Rows[n]["RecordId"].ToString() != "")
                    {
                        model.RecordId = new Guid(dt.Rows[n]["RecordId"].ToString());
                    }
                    model.UserName = dt.Rows[n]["UserName"].ToString();
                    model.Tel = dt.Rows[n]["Tel"].ToString();
                    model.Mobile = dt.Rows[n]["Mobile"].ToString();
                    model.Email = dt.Rows[n]["Email"].ToString();
                    model.Address = dt.Rows[n]["Address"].ToString();
                    model.AddCompany = dt.Rows[n]["AddCompany"].ToString();
                    model.AddDepart = dt.Rows[n]["AddDepart"].ToString();
                    model.AddUser = dt.Rows[n]["AddUser"].ToString();
                    if (dt.Rows[n]["Level"].ToString() != "")
                    {
                        model.Level = int.Parse(dt.Rows[n]["Level"].ToString());
                    }
                    if (dt.Rows[n]["UpdateTime"].ToString() != "")
                    {
                        model.UpdateTime = DateTime.Parse(dt.Rows[n]["UpdateTime"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        //*******************************************
        //功能概要       ：根据参数列表获得黑名单数据
        //参数説明       ：hsParams 参数列表
        //返回值説明     ：无
        //功能詳細       ：根据参数列表获得黑名单数据
        //作成者         ：he.jifeng 
        //作成日         ：2010-03-30
        //*******************************************
        public List<Chenxin.Lib.Hr.Entity.Hr_BlackList> GetListByCondition(System.Collections.Hashtable hsParams, out int CntOfTotal)
        {
            int PageIndex = 1;
            int PageSize = 10;
            string strWhere = "1=1";

            //欲选择字段列表 
            string FieldList = "RecordId,UserName,Tel,Mobile,Email,Address,Level,AddCompany,AddDepart,AddUser,UpdateTime";
            //子查询欲选择字段列表
            string TableFieldList = "RecordId,UserName,Tel,Mobile,Email,Address,Level,AddCompany,AddDepart,AddUser,UpdateTime";
            string OrderField = "UserName";

            //所要查询的表名
            string TableName = "Hr_BlackList";

            //类型
            if (hsParams.ContainsKey("Level"))
            { 
                strWhere = strWhere + " And Level=" + hsParams["Level"].ToString();
            }
            //姓名
            if (hsParams.ContainsKey("UserName"))
            {
                strWhere = strWhere + " And UserName='" + hsParams["UserName"].ToString() + "'";
            }
            //首字母
            if (hsParams.ContainsKey("Initial"))
            {
                strWhere = strWhere + " And Initial='" +  hsParams["Initial"].ToString() + "' ";
            }

            if (hsParams.ContainsKey("pageIndex"))
            {
                PageIndex = Convert.ToInt32(hsParams["pageIndex"]);
            }
            if (hsParams.ContainsKey("pageSize"))
            {
                PageSize = Convert.ToInt32(hsParams["pageSize"]);
            }

            DataSet ds = Chenxin.Lib.Hr.DAL.Hr_BlackList.GetList(PageSize, PageIndex, OrderField, TableName, strWhere, FieldList, TableFieldList, true);
            CntOfTotal = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
            return DataTableToList(ds.Tables[0]);
        }

        //*******************************************
        //功能概要       ：模糊搜索黑名单
        //参数説明       ：strQuery 搜索字符串
        //返回值説明     ：无
        //功能詳細       ：模糊搜索黑名单
        //作成者         ：he.jifeng 
        //作成日         ：2010-03-30
        //*******************************************
        public List<Chenxin.Lib.Hr.Entity.Hr_BlackList> GetListByQuery(string strQuery)
        {
            string strWhere = "1=1";

            strWhere = strWhere + " And UserName like '%" + strQuery + "%'";

            DataSet ds = Chenxin.Lib.Hr.DAL.Hr_BlackList.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        #endregion  成员方法
    }
}

